<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class GoodsAuthor extends Model
{
    public static function getLiveAnchor($pid,$type,$currentPage, $perPage){
        $res = ActivityGoods::where(['product_id'=>$pid])->find();
        if(!$res)return [];
        $field = 'nickname,avatar,author_id,sec_uid,room_avatar,follower_count,zan_count,title,start_time,finish_time,sale_num,sale_volume,user_count,product_id,type,create_time';
        $data = self::field($field)->where(['type'=>$type, 'product_id'=>$pid])->paginate(['page'=>$currentPage,'list_rows'=>$perPage]);
        $lives = $data->toArray();
        if($lives['data'] && $type == 2){
            foreach($lives['data'] as $k=>$v){
                $lives['data'][$k]['finish_time'] = formatTime($v['start_time'], $v['finish_time']);
                $lives['data'][$k]['start_time'] = date('Y-m-d H:i:s', $v['start_time']);
            }
        }
        return $lives;
    }
}
